package com.adlotto2.lcdns.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.adlotto2.lcdns.cronos.data.CNLottoAdFaQData;
import com.adlotto2.lcdns.cronos.datahandler.CNBaseDataParser;
import com.adlotto2.lcdns.cronos.datahandler.CNResultSet;

public class CNFaQListParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception {

		NodeList nodeList = xmlObject.getElementsByTagName("faq");
		
		NodeList title = xmlObject.getElementsByTagName("title"); 
		NodeList contents = xmlObject.getElementsByTagName("contents"); 
		
		NodeList totalCntNode = xmlObject.getElementsByTagName("totalCount");
		String totalCnt = totalCntNode.item(0).getFirstChild().getNodeValue();
		resultSet.setTotalCount(Integer.parseInt(totalCnt));
		
		int count = nodeList.getLength();
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoAdFaQData dataSet = new CNLottoAdFaQData();
			
			if(title.item(i).getFirstChild() != null)
				dataSet.faqTitle = title.item(i).getFirstChild().getNodeValue();
			
			if(contents.item(i).getFirstChild() != null)
				dataSet.faqContents = contents.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
